Skip to content

Code Quality: Reduce redundant SelectedItems updates in SelectionChanged#18495

Merged
yair100 merged 2 commits into
files-community:mainfrom
muko:fix/reduce-selection-changed-event
Jun 3, 2026
Merged

Code Quality: Reduce redundant SelectedItems updates in SelectionChanged#18495
yair100 merged 2 commits into
files-community:mainfrom
muko:fix/reduce-selection-changed-event

Conversation

@muko

@muko muko commented May 17, 2026

Copy link
Copy Markdown
Contributor

Resolved / Related Issues

When selecting files or folders, SelectionChanged is raised multiple times even when the actual selection does not change.
For example, when opening a folder by double-clicking, SelectionChanged is fired repeatedly without any real change in SelectedItems.

The root cause is that SelectedItems was always assigned from a new list instance:

SelectedItems = FileList.SelectedItems.Cast<ListedItem>().Where(x => x is not null).ToList();

Since ToList() creates a new list instance on every call, the setter was always triggered and caused unnecessary side effects (such as PropertyChanged-driven updates).

Steps used to test these changes

  • Open a file by double-clicking
  • Open a folder by double-clicking
  • Open a folder using keyboard navigation
  • Select multiple items by mouse

@yair100 yair100 added the ready for review Pull requests that are ready for review label May 17, 2026
Comment thread src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs Outdated
Comment thread src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs Outdated

@yair100 yair100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yair100 yair100 added ready to merge Pull requests that are approved and ready to merge and removed ready for review Pull requests that are ready for review labels Jun 3, 2026
@yair100
yair100 merged commit bb4f748 into files-community:main Jun 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge Pull requests that are approved and ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants